﻿using System;
using System.Runtime.Serialization;

namespace HQS.TokenInterpolation
{
    [Serializable]
    public class SyntaxException : Exception
    {
        public SyntaxException(string message, string lineNumber, string position) : base(message)
        {
            LineNumber = lineNumber;
            Position = position;
        }

        public SyntaxException(string message, Exception inner) : base(message, inner)
        {
        }

        protected SyntaxException(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            if (info != null)
            {
                OffendingText = info.GetString("offendingtext");
                Position = info.GetString("position");
                LineNumber = info.GetString("lineNumber");
            }
        }

        public string OffendingText { get; set; }

        public string LineNumber { get; set; }

        public string Position { get; set; }

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
            if (info != null)
            {
                info.AddValue("lineNumber", LineNumber);
                info.AddValue("position", OffendingText);
                info.AddValue("offendingtext", Position);
            }
        }
    }
}